import random
def get_random(rate):
    i = random.randint(-1000000000,100000000)%100
    if i>(100*rate):
        return 1
    else:
        return 0

def init(people,rate):
    a=[]     #投票结果
    for i in range(people):
        a.append(get_random(rate[i]))    #根据比例生成随机数
    return a


def vote(Temptation, people, round, growth):
    rate = [Temptation]*people     #初始每个人的投票率
    a=init(people,rate)    #第一轮投票
    result = []    #要输出的所有投票率
    for i in range(len(a)):
        if a[i] == 1:  # 投票
            rate[i] = rate[i] + growth
    result.append(a.count(0) / people)

    for i in range(1,round):
        for i in range(len(a)):
            if a[i]==1:   #投票
                rate[i] = rate[i]+growth

        a = init(people,rate)
        result.append(a.count(0)/people)
    return result

if __name__ == '__main__':
    arr = ['against', 'accept']
    Temptation = [0.2, 0.4, 0.6]   #投票率

    people = 1000
    round = 14
    growth = 0.01


    #投票率0.2,0.4,0.6
    #分别设置growth为0.2,0.4，0.5,0.6
    print("奖励为0.2：")
    for i in range(len(Temptation)):
        a = vote(Temptation[i], people, round, 0.02)
        print(a)

    print("奖励为0.4：")
    for i in range(len(Temptation)):
        a = vote(Temptation[i], people, round, 0.04)
        print(a)

    print("奖励为0.5：")
    for i in range(len(Temptation)):
        a = vote(Temptation[i], people, round, 0.05)
        print(a)

    print("奖励为0.6：")
    for i in range(len(Temptation)):
        a = vote(Temptation[i], people, round, 0.06)
        print(a)

